/*t062wrAbzsHyGvc+J5WsZGfSf8HfbFTTE9NsNT/une6jp5RsH2IrbRBQMXT0ZdDD*/
/*
 * @Author: xiahui
 * @PageInfo: 付款计划编辑后
 * @Date: 2019-03-08 10:33:55
 * @Last Modified by: huoyzh
 * @Last Modified time: 2020-08-14 15:24:19
 */
import { ajax } from 'nc-lightapp-front';
import { AREA, URL, PAGECODE, FIELDS } from '../../constance';
import { showWarningInfo } from '../../../../../scmpub/scmpub/pub/tool/messageUtil';
import { createGridAfterEventData, processGridEditResult } from '../../../../../scmpub/scmpub/pub/tool/afterEditUtil';
import { simplifyDataByFields } from '../../../../../scmpub/scmpub/pub/tool/simplifyDataUtil';

export default function bodyAfterEvent(props, moduleId, key, value, rows, index, record) {
	let afterKeys = [ FIELDS.dbegindate, FIELDS.denddate, FIELDS.iitermdays, FIELDS.norigmny, FIELDS.nrate ];

	if (afterKeys.includes(key)) {
		// 新旧相同，不触发
		let newvalue = rows[0].newvalue.value == '' ? null : rows[0].newvalue.value;
		let oldvalue = rows[0].oldvalue.value == '' ? null : rows[0].oldvalue.value;
		if (newvalue == oldvalue) {
			return;
		}

		let userObject = { rows: [] };
		if (FIELDS.norigmny == key || FIELDS.nrate == key) {
			let allRows = props.editTable.getAllRows(AREA.listTableId);
			let editRowPk = record.values[FIELDS.pk_ct_pu].value;
			allRows.map((row, i) => {
				if (editRowPk == row.values[FIELDS.pk_ct_pu].value && index != i) {
					userObject.rows.push(row);
				}
			});
			userObject = simplifyDataByFields(userObject, true, [ FIELDS.nrate, FIELDS.norigmny, FIELDS.nmny ]);
		}

		let datas = createGridAfterEventData(
			props,
			PAGECODE.listPagecode,
			AREA.listTableId,
			moduleId,
			key,
			rows,
			index,
			userObject
		);

		ajax({
			url: URL.bodyafteredit,
			data: datas,
			success: (res) => {
				let { success, data } = res;
				if (success && data) {
					if (data.userObject.error) {
						showWarningInfo(null, data.userObject.error);
					}
					processGridEditResult(props, moduleId, data, index);
					props.editTable.updateDataByRowId(AREA.listTableId, data.userObject, false, false);
				}
			}
		});
	}
}

/*t062wrAbzsHyGvc+J5WsZGfSf8HfbFTTE9NsNT/une6jp5RsH2IrbRBQMXT0ZdDD*/